package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;
//111
@Data
@Slf4j
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {

    private String pubKeyPath;
    private String priKeyPath;

    private PublicKey publicKey;
    private PrivateKey privateKey;

    private AuthUser user = new AuthUser(); //对象需要初始化 再注入

    @Data
    public class AuthUser{
        private Integer expire;
        private String cookieName;
        private String cookieDomain;
        private Integer refreshTime;
    }

    //不能使用构造方法 获得公钥私钥
    //该类是交给了springIOC管理的
    //先执行构造方法再执行依赖注入 因此参数没有被注入就创建对象是不对的
    @PostConstruct // 在ioc对象创建成功之后执行该方法
    public void createKey() throws Exception {
        this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
    }

}